package edu.ustb.mis.dm.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import edu.ustb.mis.dm.Constants;
import edu.ustb.mis.dm.impl.data.TextInputDataPrepare;
import edu.ustb.mis.dm.interfaces.data.DataPrepare;
import edu.ustb.mis.dm.model.unit.impl.Instance;

public class WeightUtils {
	public static void main(final String[] args) {
		final Map<Integer, Double> m = weight(Constants.ZOO_TRANSLATE_NAME);
		System.out.println(m);
	}

	public static Map<Integer, Double> weight(final String data_set_name) {
		final DataPrepare<Instance> dp = new TextInputDataPrepare(data_set_name);
		final List<Instance> data = dp.initData();
		final Map<Integer, Double> weightMap = new HashMap<Integer, Double>();
		final double total = data.size();
		for (final Instance instance : data) {
			for (final Integer key : instance.getAttributeSet()) {
				if (weightMap.containsKey(key)) {
					weightMap.put(key, weightMap.get(key) + 1);
				} else {
					weightMap.put(key, 1d);
				}
			}
		}
		for (final Entry<Integer, Double> entry : weightMap.entrySet()) {
			entry.setValue(Math.log10(total / entry.getValue()));
		}
		return weightMap;
	}
}
